
import java.awt.Color;

import javax.swing.JFrame;

import java.awt.Font;
import fr.lri.swingstates.canvas.CPolyLine;
import fr.lri.swingstates.canvas.CRectangle;
import fr.lri.swingstates.canvas.Canvas;
import fr.lri.swingstates.gestures.AbstractClassifier;
import fr.lri.swingstates.gestures.rubine.RubineClassifier;

public class GestureRecognition extends JFrame {

    public static final int WIDTH_TOOL = 75;
    public static final int HEIGHT_TOOL = 60;
    public static final String TITLE = "Editeur graphique a reconnaissance de gestes";
    Canvas canvas;

    public GestureRecognition() {
        super(TITLE);
        RubineClassifier classifier = null;
        classifier = RubineClassifier.newClassifier("./res/vocabulaire.cl");
        setSize(WIDTH_TOOL * (classifier.getClasses().size() + 3), 600);
        canvas = new Canvas(600, 600);
        recognizedGestures(classifier);
        InkMachine sm = new InkMachine(classifier, canvas);

        // Add a canvas to the swing glasspane to draw the pie menu.
        setGlassPane(canvas);
        getGlassPane().setVisible(true);
        canvas.setOpaque(false);

        // Attach pie menu machine to this canvas
        sm.attachTo(canvas);

        add(canvas);
        setVisible(true);
    }

    void recognizedGestures(AbstractClassifier classifier) {
        CRectangle bar = new CRectangle(10.0, 25.0, WIDTH_TOOL * 2, HEIGHT_TOOL);
        CRectangle bar2 = new CRectangle(WIDTH_TOOL * 2, 25.0, WIDTH_TOOL * 5, HEIGHT_TOOL);

        bar.setFillPaint(Color.lightGray);
        canvas.addShape(bar);
        canvas.addShape(bar2);
        canvas.newText(WIDTH_TOOL * (classifier.getClasses().size() + .3), 45, " Geste reconnu : ", new Font("Verdana", Font.PLAIN, 14));

        canvas.newText(10, 10, "Gestes possibles : ");
        for (int i = 0; i < classifier.getClasses().size(); i++) {
            CPolyLine gest = classifier.getRepresentative(classifier.getClasses().get(i));
            gest.addTo(canvas).scaleBy(25 / gest.getHeight(), 25 / gest.getWidth()).translateTo(50 + 70 * i, 50);
            canvas.newText(0, 0, classifier.getClasses().get(i)).translateTo(gest.getCenterX(), bar.getMaxY() - 10);
        }
    }

    public static void main(String[] args) {
        GestureRecognition gr = new GestureRecognition();
        gr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}


